import request from "@/utils/request";

// 用户分页查询
export const queryUserPageApi = (params) =>
  request.get("/users", { params: params });

// 根据Id查询用户
export const getUserByIdApi = (id) => request.get(`/users/${id}`);

// 添加用户
export const addUserApi = (data) => request.post("/users", data);

// 修改用户
export const updateUserApi = (data) => request.put("/users", data);

// 删除用户
export const deleteUserApi = (id) => request.delete(`/users/${id}`);

// 批量删除用户
export const batchDeleteUserApi = (ids) => {
  // 将数组转换为逗号分隔的字符串
  const idsString = Array.isArray(ids) ? ids.join(",") : ids;
  return request.delete(`/users/${idsString}`);
};

// 文件上传接口
export const uploadImageApi = (file) => {
  const formData = new FormData();
  formData.append("image", file);
  return request.post("/upload", formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
};
